﻿using NicoView.Model.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NicoView.Model.Service
{
    /// <summary>
    /// シリアライズ可能な視聴ユーザ情報リスト
    /// </summary>
    public class SerializableNicoEncounterUserList
    {
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public SerializableNicoEncounterUserList()
        {
            UserList = new List<SerializableNicoEncounterUser>();
        }

        /// <summary>
        /// 視聴ユーザリスト
        /// </summary>
        public ICollection<SerializableNicoEncounterUser> UserList;

        public void Marge(ICollection<SerializableNicoEncounterUser> list)
        {
            foreach (var user in list)
            {
                var serchResult = from user2 in this.UserList
                                  where user2.Id == user.Id
                                  select user2;

                if (serchResult.Count() > 0)
                {
                    this.UserList.Remove(serchResult.First());

                }

                this.UserList.Add(user);
            }
        }

        /// <summary>
        /// 保存する視聴ユーザを選定
        /// </summary>
        public void SelectionSaveUsers()
        {
            List<SerializableNicoEncounterUser> list = new List<SerializableNicoEncounterUser>();
            foreach (var user in this.UserList)
            {
                if (user.IsSave())
                {
                    list.Add(user);
                }
            }

            this.UserList = list;
            
        }
    }
}
